package china.accountinghelper.database;

import java.util.Map;

import com.xdroid.base.SQLiteDALBase;

import android.content.ContentValues;
import android.database.Cursor;
import china.wc.tallyhelper.model.ModelCategory;

/**
 * 操作ModelCategory类的SQLiteDatabaseDAL类
 * 
 * 
 * 
 * @author 王超
 * 
 */
public class SQLiteDALModelCategory extends SQLiteDALBase<ModelCategory>
{

    public SQLiteDALModelCategory(Class<ModelCategory> pModelClass)
    {
        super(pModelClass);
    }

    @Override
    protected ContentValues toContentValues(ModelCategory pModelCategory)
    {
        Map<String, String> _AllFieldColumn = getFieldColumnMap();
        ContentValues _ContentValues = new ContentValues();

        for (String _FieldName : _AllFieldColumn.keySet()) {
            if ("mName".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelCategory.getName());
            } else if ("mCreateTime".equals(_FieldName)) {
                _ContentValues.put(_AllFieldColumn.get(_FieldName), pModelCategory.getCreateTime().getTimeInMillis());
            }
        }

        return _ContentValues;
    }

    @Override
    protected ModelCategory toModel(Cursor pCursor)
    {
        ModelCategory _ModelCategory = new ModelCategory();

        _ModelCategory.setID(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mID"))));
        _ModelCategory.setName(pCursor.getString(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mName"))));
        _ModelCategory.setCreateTime(pCursor.getLong(pCursor.getColumnIndexOrThrow(getFieldColumnMap().get("mCreateTime"))));

        return _ModelCategory;
    }

}
